// 导入axios   cnpm i axios@0.24.0 -S
import axios from "axios";

// 创建axios实例
const request = axios.create({
  // baseURL: "http://kg.zhaodashen.cn/mt/admin/",
  baseURL: "/api",
  timeout: 6000,
  headers: {
    "content-type": "application/x-www-form-urlencoded",
  },
});

// 拦截器
request.interceptors.request.use(
  (config) => {
    config.headers.token =
      localStorage.getItem("token") || "9201591ba0eb36c8abaea2854274f5082";
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);
request.interceptors.response.use(
  (response) => {
    return response.data;
  },
  (error) => {
    return Promise.reject(error);
  }
);

// 导出request对象
export default request;
